package com.example.baselibrary.utils

import android.util.Log
import java.util.*
import kotlin.collections.HashMap

object SignUtils {
    /**
     * 需要生成的 hasmap
     * t 时间戳
     */
    fun getSign(hasMap: HashMap<String, String>, t: String): String {
        //参与生成sign的数据
        val mySignMap: HashMap<String, String> = HashMap()
        mySignMap.putAll(hasMap)
        mySignMap["t"] = t
        Log.e("aa", "----------排序前===$mySignMap")
        val sorted: TreeMap<String, String> = TreeMap(mySignMap)
        Log.e("aa", "----------排序后===$sorted")
        var str = ""
        sorted.forEach {
            str += it.key + "=" + it.value+"&"
        }
        str=str.substring(0,str.length-1)
        Log.e("aa", "-----str==$str")
        val str1 = MD5Util.md5(str)
        Log.e("aa", "-----str1==$str1")
        val str2 = MD5Util.md5(str1 ,"f3aede46f789f8e4aea90610c6dd8551")
        Log.e("aa", "-----str2==$str2")
        return str2
    }

}